package com.ruoyi.product.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.product.domain.GoodsResource;
import com.ruoyi.product.service.IGoodsResourceService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商品资源Controller
 * 
 * @author ruoyi
 * @date 2021-04-29
 */
@RestController
@RequestMapping("/resource")
public class GoodsResourceController extends BaseController
{
    @Autowired
    private IGoodsResourceService goodsResourceService;

    /**
     * 查询商品资源列表
     */
    @PreAuthorize(hasPermi = "product:resource:list")
    @GetMapping("/list")
    public TableDataInfo list(GoodsResource goodsResource)
    {
        startPage();
        List<GoodsResource> list = goodsResourceService.selectGoodsResourceList(goodsResource);
        return getDataTable(list);
    }

    /**
     * 导出商品资源列表
     */
    @PreAuthorize(hasPermi = "product:resource:export")
    @Log(title = "商品资源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsResource goodsResource) throws IOException
    {
        List<GoodsResource> list = goodsResourceService.selectGoodsResourceList(goodsResource);
        ExcelUtil<GoodsResource> util = new ExcelUtil<GoodsResource>(GoodsResource.class);
        util.exportExcel(response, list, "商品资源数据");
    }

    /**
     * 获取商品资源详细信息
     */
    @PreAuthorize(hasPermi = "product:resource:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(goodsResourceService.selectGoodsResourceById(id));
    }

    /**
     * 新增商品资源
     */
    @PreAuthorize(hasPermi = "product:resource:add")
    @Log(title = "商品资源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsResource goodsResource)
    {
        return toAjax(goodsResourceService.insertGoodsResource(goodsResource));
    }

    /**
     * 修改商品资源
     */
    @PreAuthorize(hasPermi = "product:resource:edit")
    @Log(title = "商品资源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsResource goodsResource)
    {
        return toAjax(goodsResourceService.updateGoodsResource(goodsResource));
    }

    /**
     * 删除商品资源
     */
    @PreAuthorize(hasPermi = "product:resource:remove")
    @Log(title = "商品资源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(goodsResourceService.deleteGoodsResourceByIds(ids));
    }
}
